//index.js
//获取应用实例
const app = getApp()
const api = require('../../utils/api.js');
Page({
	data: {
		userInfo: {},
		hasUserInfo: false,
		userList:[],
		point:0,
		redTotal:0,
	},
	toBaby: function() {
		wx.navigateTo({
			url: '../baby/baby'
		})
	},
	tapName:function(){
		wx.navigateTo({
			url: '../user/balance'
		})
	},
	toRedBag:function(){
		wx.navigateTo({
			url: '../fetchred/redlist'
		})
	},
	toHideInfo:function(){
		wx.navigateTo({
			url: '../user/hideInfo'
		})
	},
	onShow: function() {
		let _this = this;
		_this.setData({
			userInfo: app.globalData.userInfo,
			hasUserInfo: true
		})
		_this.getBobyList(app.globalData.userId);
	    _this.getUserPoint(app.globalData.userId);
	    _this.getRedTotal(app.globalData.userId);
	},
	onPullDownRefresh:function(){
		this.onShow();
		wx.stopPullDownRefresh();
	},
	getBobyList:function(ownerId){
		let _this = this;
		api.getBobyList({
			data: {
				ownerId: ownerId,
				pageSize: "100",
				pageNum: "1",
			},
			success: function(res) {
				if(res.data.code == 0) {
					res.data.list.rows.forEach(function(item){
						item.birthDay = item.birthDay.substr(0,10);
					});
					_this.setData({
						userList: res.data.list.rows,
					});
				}
			},
		});
	},
	getUserPoint:function(ownerId){
		let _this = this;
		api.getUserPoint({
			data: {
				userId: ownerId,
			},
			success: function(res) {
				if(res.data.code == 0) {
					let point = res.data.point;
					_this.setData({
						point: point == null?0:point,
					});
				}
			},
		});
	},
	getRedTotal:function(ownerId){
		let _this = this;
		api.getRedTotal({
			data: {
				ownerId: ownerId,
				bagStatus:"0"
			},
			success: function(res) {
				if(res.data.code == 0) {
					let total = res.data.total;
					_this.setData({
						redTotal: total == null?0:total,
					});
				}
			},
		});
	},
})